<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./../../Template/generalTemplate.xhtml">



            <ui:define name="content">

                <h:form id="form1">
                    <f:view beforePhase="#{manageIncomingBillManagedBean.initView}">
                        <p:panel style="height:495px;" header="Incoming Bill Record Detail" >
                            <p:commandLink style="margin-right:10px; position:relative;float:right" value ="View All Incoming Bill Records" action="#{manageIncomingBillManagedBean.viewAll}"/>
                            <br/>
                            <hr/>
                            <div style="height:375px; overflow: auto; border-bottom:solid #AFAFAF 1px;">

                                <p:growl id="growl1" showDetail="true" /> 
                                <h:outputText style="color:red; font-size:15px;" value="The Incoming Bill Is Abolished" rendered="#{manageIncomingBillManagedBean.incomingBillRecord.abolished}"/> <br/> 
                                <h:panelGrid columns ="2" cellpadding="3">
                                    <h:outputText style="color:blue; font-size:13px;" value ="Payment is Needed" rendered ="#{manageIncomingBillManagedBean.paymentNeed}"/> 
                                    <h:outputText value ="" rendered ="#{manageIncomingBillManagedBean.paymentNeed}"/> 
                                    <h:outputText style="color:green; font-size:13px;" value ="Payment Cleaned" rendered ="#{!manageIncomingBillManagedBean.paymentNeed}"/> 
                                    <h:outputText value ="" rendered ="#{!manageIncomingBillManagedBean.paymentNeed}"/> 
                                    <h:outputText value="Bill Record ID: "/>
                                    <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.id}"/> 
                                    <h:outputText value="Supplier Name(From): "/>
                                    <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.supplierName}"/>
                                    <h:outputText value="Created By:"/>
                                    <h:outputText value="#{manageIncomingBillManagedBean.employeeName}"/> 
                                    <h:outputText value= "Create Date"/> 
                                    <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.createDate}"> 
                                        <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                    </h:outputText>
                                    <h:outputText value= "Due Date"/> 
                                    <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.dueDate}"> 
                                        <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                    </h:outputText>
                                    <h:outputText style="color:red;" value="Expired" rendered="#{manageIncomingBillManagedBean.isDue}"/>
                                    <h:outputText value="" rendered="#{manageIncomingBillManagedBean.isDue}"/>   
                                    <h:outputText value= "Total Due:"/>
                                    <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.totalDue}"/> 
                                    <h:outputText value= "Amount Payable:"/>
                                    <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.amountPayable}"/>     
                                    <h:outputText value="Voucher: "/>
                                    <h:outputText value="No Voucher Created" rendered="#{!manageIncomingBillManagedBean.voucherHas}"/>
                                    <p:commandLink value="Show" rendered="#{manageIncomingBillManagedBean.voucherHas}" oncomplete="dlg3.show()"/>
                                    
                                </h:panelGrid>
                                <p:fieldset legend="RawMaterialPurchasingOrder Detail" toggleable="true" toggleSpeed="500"  
                                            toggleListener="#{manageIncomingBillManagedBean.handleToggle}"  
                                            onToggleUpdate="deliveryInfo" collapsed="true">  

                                    <p:dataTable style ="margin-top:10px;" value ="#{manageIncomingBillManagedBean.formRMPOrderList()}" var="o">
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="RM Purchasing Order Id" />
                                            </f:facet>
                                            <h:outputText value="#{o.id}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">Supplier Name</f:facet>
                                            #{o.supplier.supplierName}
                                        </p:column> 
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Line Item"/>
                                            </f:facet>
                                            <p:commandLink value="Show" onclick="dlg2.show()"/>
                                            <p:dialog header="RawMaterial Purchasing Order LineItemList" widgetVar="dlg2" resizable="true" width="500">  
                                                <p:dataTable value="#{manageIncomingBillManagedBean.rmLineItemList}" var="lineItem">
                                                    <p:column>
                                                        <f:facet name="header">RawMaterial</f:facet>
                                                        #{lineItem.rawMaterial.rawMaterialName}
                                                    </p:column>  
                                                    <p:column>
                                                        <f:facet name="header">Purchased Amount</f:facet>
                                                        #{lineItem.lotQuantity}
                                                    </p:column>  

                                                    <p:column>
                                                        <f:facet name="header">Subtotal Price</f:facet>
                                                        #{lineItem.cumAmount}
                                                    </p:column>  
                                                    <p:column>
                                                        <f:facet name="header">Reception Status</f:facet>
                                                        <h:outputText style="color:blue;" value="Received" rendered="#{lineItem.received}"/>
                                                        <h:outputText style="color:red;" value="Not Received" rendered="#{!lineItem.received}"/>    
                                                    </p:column>  
                                                </p:dataTable>   
                                            </p:dialog>  
                                        </p:column>    
                                        <p:column>
                                            <f:facet name="header">Create Date</f:facet>
                                            <h:outputText value="#{o.dateGenerated}">
                                                <f:convertDateTime pattern ="dd/MM/yyyy"/>
                                            </h:outputText>    
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Total Amount</f:facet>
                                            #{o.totalPrice}
                                        </p:column>

                                    </p:dataTable> 

                                </p:fieldset>  
                            </div>
                            <p:commandButton style="margin-top:20px; " value="Abolish Bill Record" onclick="confirmation.show()" rendered="#{!manageIncomingBillManagedBean.incomingBillRecord.abolished}"/> 
                            <p:commandButton style="margin-right:5px; margin-top:20px; position:relative; float:right" rendered="#{!manageIncomingBillManagedBean.incomingBillRecord.abolished}" value="Create Voucher" update="growl1" onclick= "dlg.show()"/>
                            <p:dialog header="Enter The Amount of Payment Made" widgetVar="dlg" resizable="false">  

                                <h:panelGrid columns="2" style="margin-bottom:10px">  
                                    <h:outputText value="Amount:" />  
                                    <p:inputText value="#{manageIncomingBillManagedBean.payment}" />  
                                </h:panelGrid>  
                                <p:commandButton value="Submit" ajax="false" action="#{manageIncomingBillManagedBean.createVoucher}" update="form1" oncomplete="dlg.hide();"/>  

                            </p:dialog> 
                            <p:confirmDialog message="Are you sure to abolish the invoice?"  
                                             showEffect="bounce" hideEffect="explode"  
                                             header="Abolish Invoice" severity="alert" widgetVar="confirmation">  

                                <p:commandButton value="Yes Sure" update="form1" ajax="true" oncomplete="confirmation.hide()"  
                                                 action="#{manageIncomingBillManagedBean.abolishIncomingBill}" />  
                                <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   

                            </p:confirmDialog>
                            <p:dialog widgetVar="dlg3" header="Voucher Detail" width="600">
                                <p:outputPanel style="margin-top:10px; margin-left:5px; width:800px;">   
                                    <h:panelGrid columns="2" cellpadding ="5">
                                        <h:outputText value="Receipt ID:"/>
                                        <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.voucher.id}"/>
                                        <h:outputText value="Issued By:"/>
                                        <h:outputText value="#{manageIncomingBillManagedBean.employeeName}"/>
                                        <h:outputText value="Create Date:"/>
                                        <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.voucher.paymentDate}">
                                            <f:convertDateTime pattern ="dd/MM/yyyy"/>
                                        </h:outputText>   
                                        <h:outputText value="Amount Paid:"/>
                                        <h:outputText value="#{manageIncomingBillManagedBean.incomingBillRecord.voucher.amountPaid}"/>
                                    </h:panelGrid>   

                                </p:outputPanel>
                            </p:dialog>

                        </p:panel>
                    </f:view>  
                </h:form>

            </ui:define>


        </ui:composition>

    </body>
</html>
